import sys
try:
    import json
except ImportError:
    import simplejson as json

out = None
msgid = None
msgstr = None
i18n = {}

for line in open(sys.argv[1]).xreadlines():
    line=line.strip()
    if not line or line[0]=='#': continue
    if line.startswith("msgid"):
        msgstr = out
        out = ""
        line = line[5:]
        if msgstr is not None and msgid:
            i18n[msgid] = msgstr
    elif line.startswith("msgstr"):
        msgid = out
        out = ""
        line = line[6:]
    out = out + eval(line).decode('utf-8')

if msgstr is not None and msgid:
    msgstr = out
    i18n[msgid] = msgstr

print json.dumps(i18n)

